//
//  ReconciliationMenuView.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/4/1.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "ReconciliationMenuView.h"

@interface ReconciliationMenuView ()
@property (nonatomic ,assign) NSInteger lastSelectBtnTag;
@end

@implementation ReconciliationMenuView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createBtn];
    }
    return self;
}

- (void)createBtn {

    NSArray *titleArr = @[@"查账",@"提现"];
    for (int i = 0; i < 2; i ++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        btn.frame = CGRectMake(size_width/2 * i, 0, size_width/2, 46);
        [btn setTitle:titleArr[i] forState:(UIControlStateNormal)];
        [btn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:(UIControlStateNormal)];
        btn.titleLabel.font = [UIFont systemFontOfSize:16];
        btn.tag = 200 + i;
        [btn addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
        [self addSubview:btn];
        self.lastSelectBtnTag = 200;
    }
    
    
    CGFloat lineViewww = self.frame.size.width/2;
    CGFloat lineVieww = lineViewww - 44;
    // 跟随移动的横线
    UIView *lineView =[[UIView alloc] initWithFrame:(CGRectMake(22, self.frame.size.height - 2, lineVieww, 2))];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#ff9900"];
    lineView.tag = 2222;
    [self addSubview:lineView];
    
    // 底部线条
    UIView *btmLineView = [[UIView alloc] initWithFrame:(CGRectMake(0, self.frame.size.height -1, size_width, 1))];
    btmLineView.backgroundColor = [UIColor colorWithHexString:@"#dddddd"];
    [self addSubview:btmLineView];
}

- (void)click:(UIButton *)sender {

    NSInteger tag = sender.tag;
    UIButton *lasetSelectBtn = [self viewWithTag:self.lastSelectBtnTag];
    [lasetSelectBtn setTitleColor:[UIColor darkGrayColor] forState:(UIControlStateNormal)];
    [sender setTitleColor:[UIColor colorWithHexString:@"#ff9900"] forState:(UIControlStateNormal)];
    self.lastSelectBtnTag = tag;
    UIView *lineView = [self viewWithTag:2222];
    [UIView animateWithDuration:0.5 animations:^{
          lineView.frame = CGRectMake(sender.frame.origin.x+22, lineView.frame.origin.y, lineView.frame.size.width, lineView.frame.size.height);
    }];
    if (self.delegate && [self.delegate respondsToSelector:@selector(buttonClickWithTag:)]) {
        [self.delegate buttonClickWithTag:sender.tag];
    }

}


@end
